package com.activenetwork.smlite.testcase.events.createEvents.selectComponents;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;

import com.activenetwork.smlite.snippet.EventsSnippet;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.EnvContext;
import com.activenetwork.util.verification.gson.FailureAssertion;
import com.activenetwork.util.verification.gson.FailurePoint;

public class SelectComponents002 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(SelectComponents002.class);
	
	@Test
	public void Verify_short_description_of_the_item_is_displayed_when_a_user_hovers_over_it(){
		loginBusiness.login();
		EventsSnippet.gotoAddEventPage();
		
		// Find each component checkbox
		// When check it on, check the corresponding div's class property 
		// should not have hide content so that the right part introduction will display
		WebDriver driver = EnvContext.webDriverTL.get();
		List<WebElement> ps = driver.findElements(By.xpath("//div[contains(@class,'autotest-html-eventbasicsubview')]//p[@class='mouseoverClass']"));		
		
		
		for(WebElement p : ps){
			p.click();
			String componentName = p.findElement(By.xpath("./input")).getAttribute("data-component-name").trim();
			if(componentName.equals("venueSourcing")){
				checkIntroduction(driver, "#venueSourcing", "Sourcing");
			}else if(componentName.equals("socialMedia")){
				checkIntroduction(driver, "#socialMedia", "Social Media");
			}else if(componentName.equals("eventWebsite")){
				checkIntroduction(driver, "#eventWebsite", "Website");
			}else if(componentName.equals("email")){
				checkIntroduction(driver, "#email", "Email");
			}else if(componentName.equals("attendeeDirectories")){
				checkIntroduction(driver, "#attendeeDirectories", "Attendee Directories");
			}else if(componentName.equals("registrationform")){
				checkIntroduction(driver, "#registrationform", "Registration Form");
			}else if(componentName.equals("themedesigner")){
				checkIntroduction(driver, "#themedesigner", "Theme Designer");
			}else if(componentName.equals("mobile")){
				checkIntroduction(driver, "#mobile", "Mobile");
			}else if(componentName.equals("labelAndBadges")){
				checkIntroduction(driver, "#labelAndBadges", "Label and Badges");
			}else if(componentName.equals("kiosk")){
				checkIntroduction(driver, "#kiosk", "Kiosk");
			}else if(componentName.equals("reports")){
				checkIntroduction(driver, "#reports", "Reports");
			}else if(componentName.equals("customReports")){
				checkIntroduction(driver, "#customReports", "Custom Reports");
			}else if(componentName.equals("surveys")){
				checkIntroduction(driver, "#surveys", "Surveys");
			}else{
				EnvContext.failurePointTL.get().add(new FailurePoint(
						SelectComponents002.class.getName(), 
						"Verify mouse over action display introduction", 
						componentName + " is unkown for checking"));
			}
		
			
		}
		
		loginBusiness.logout();
		FailureAssertion.pop(SelectComponents002.class);
	}
	
	private void checkIntroduction(WebDriver driver, String introductionDivCssSelector, String componentName){
		WebElement div = driver.findElement(By.cssSelector(introductionDivCssSelector));
		String value = div.getAttribute("class").trim();
		if(StringUtils.contains(value, "hide")){
			EnvContext.failurePointTL.get().add(new FailurePoint(
					SelectComponents002.class.getName(), 
					"Verify mouse over action display introduction", 
					componentName + " part does not display"));
		}
	}
}
